package com.qys.livesMall.system.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.enums.SystemMessageEnum;
import com.qys.livesMall.system.model.dto.sys.PlatformAdvertisementDto;
import com.qys.livesMall.system.model.dto.sys.PlatformAdvertisementQueryPackageDto;
import com.qys.livesMall.system.model.dto.sys.PlatformAdvertisementStateDto;
import com.qys.livesMall.system.model.vo.sys.PlatformAdvertisementVo;
import com.qys.livesMall.system.service.H2PlatformAdvertisementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台广告管理 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-07-05
 */
@Tag(name = "平台广告管理", description = "平台广告管理")
@RestController
@RequestMapping("/platformAdvertisement")
public class H2PlatformAdvertisementController {

    @Resource
    private H2PlatformAdvertisementService h2PlatformAdvertisementService;

    @Operation(summary = "添加平台广告管理")
    @PostMapping("/add")
    public R add(@RequestBody @Validated PlatformAdvertisementDto platformAdvertisementDto){
        return h2PlatformAdvertisementService.add(platformAdvertisementDto)? R.ok():R.fail();
    }

    @Operation(summary = "修改平台广告管理")
    @PostMapping("/update")
    public R update(@RequestBody @Validated PlatformAdvertisementDto platformAdvertisementDto){
        if (null == platformAdvertisementDto.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        return h2PlatformAdvertisementService.update(platformAdvertisementDto)? R.ok():R.fail();
    }

    @Operation(summary = "删除平台广告管理")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable Long id){
        h2PlatformAdvertisementService.removeById(id);
        return R.ok();
    }

    @Operation(summary = "查询平台广告管理列表")
    @PostMapping("query")
    public R<IPage<PlatformAdvertisementVo>> query(@RequestBody @Validated PlatformAdvertisementQueryPackageDto dto){
        return R.ok(h2PlatformAdvertisementService.query(dto));
    }

    @Operation(summary = "查询平台广告管理详情")
    @GetMapping(value = "/info/{id}")
    public R<PlatformAdvertisementVo> info(@PathVariable Long id){
        return R.ok(h2PlatformAdvertisementService.info(id));
    }

    @Operation(summary = "平台广告管理 上下架")
    @PostMapping("/state")
    public R state(@RequestBody @Validated PlatformAdvertisementStateDto dto){
        if (null == dto.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        return h2PlatformAdvertisementService.state(dto)? R.ok():R.fail();
    }
}
